package cn.hsa.xxx.bookData.controller;


import cn.hsa.hsaf.core.framework.web.WrapperResponse;
import cn.hsa.xxx.bookData.bo.BookInventoryBO;
import cn.hsa.xxx.api.dto.BookInventoryDTO;
import cn.hsa.xxx.api.service.BookInventoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/web/bookData/bookInventory")
@RestController
@Slf4j
public class BookInventoryController {

    @Autowired
    private BookInventoryService bookInventoryService;

    @PostMapping("/addBookInventory")
    public WrapperResponse<BookInventoryDTO> addBookInventory(@RequestBody BookInventoryDTO bookInventoryDTO) {
        BookInventoryDTO result = bookInventoryService.add(bookInventoryDTO);
        return WrapperResponse.success(result);
    }

    @PostMapping("/deleteBookInventory")
    public WrapperResponse<String> deleteBookInventory(@RequestParam String id) {
        String result = bookInventoryService.delete(id);
        return WrapperResponse.success(result);
    }

    @GetMapping("/getBookInventoryById")
    public WrapperResponse<BookInventoryDTO> getBookInventory(@RequestParam String id) {
        BookInventoryDTO result = bookInventoryService.get(id);
        return WrapperResponse.success(result);
    }

    @PostMapping("/updateBookInventory")
    public WrapperResponse<String> updateBookInventory(@RequestBody BookInventoryDTO bookInventoryDTO) {
        String str = bookInventoryService.update(bookInventoryDTO);
        return WrapperResponse.success(str);
    }

    @GetMapping("/page")
    public WrapperResponse<List<BookInventoryDTO>> getPageBookInventory(int pageNo, int pageSize) {
        List<BookInventoryDTO> bookInventoryDTOList = bookInventoryService.getPage(pageNo, pageSize);
        return WrapperResponse.success(bookInventoryDTOList);
    }


    @Autowired
    BookInventoryBO bookInventoryBO;
    @GetMapping("/getByBookUuid")
    public WrapperResponse<BookInventoryDTO> getBookInventoryByBookUuid(@RequestParam String id) {
        BookInventoryDTO result = bookInventoryBO.get(id);
        return WrapperResponse.success(result);
    }
}
